def make_dirs(path):
	if not os.path.isdir(path):
		os.makedirs(path)


def test(filepath, row_cnt, suffix_type='-d'):
	root_path = os.getcwd()
	prefix = filepath.split('.')[-2]
	tmp_dir = '/tmp/'
	make_dirs(root_path+tmp_dir)

	command = "split -l%d -a2 %s %s %s" % (row_cnt, suffix_type, filepath, root_path+tmp_dir+'/'+prefix)
	os.system(command)
	filelist = os.listdir(root_path+tmp_dir)

	return [root_path+fn for fn in filelist]

def handle(filename):
    count = 0
    print filename

    # count = len(open(filename,'rU').readlines())
    # print count
    start = time.time()
    with open(filename, 'r') as f:
        for line in f:
            # print line.split("\t")[1]
            count += 1
    end = time.time()
    print 'Task %s runs %0.2f seconds. %s' % (filename, (end - start), count)
            
if __name__ == "__main__":
    import sys,os,time
    from multiprocessing import Pool
    filelist = os.listdir('tmp')
    m = ['tmp/'+fn for fn in filelist]
    start = time.time()

    pool = Pool(2)

    pool.map(handle, m)
    pool.close()
    pool.join()

    end = time.time()
    print 'Task  runs %0.2f seconds.' % ((end - start))
